<!doctype html>
<html lang="en">
  <head>
    <th:block th:include="include :: desk-header" />
  </head>

  <body>

  <th:block th:include="include :: desk-top" />

    <div class="container-fluid">
      <div class="row">

        <th:block th:include="include :: desk-menu" />

        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">

          <h2 class="sub-header">用户列表</h2>
          <div class="table-responsive">
            <table class="table table-striped table-hover">
              <thead>
                <tr>
                  <th>#</th>
                  <th>账号</th>
                  <th>姓名</th>
                  <th>状态</th>
                  <th>角色</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>

                <tr th:each="user:${userlist}">
                  <td th:text="${user.id}">ipsum</td>
                  <td th:text="${user.account}">Lorem</td>
                  <td th:text="${user.name}"></td>
                  <td th:if="${user.locked eq 1}"><span class="glyphicon glyphicon glyphicon-remove" style="color:red;"></span> 禁用</td>
                  <td th:if="${user.locked eq 0}"><span class="glyphicon glyphicon glyphicon-ok" style="color:green;"></span> 正常</td>
                  <td th:text="${roles.get(user.role).getName()}">sit</td>
                  <td>
                    <button type="button" class="btn btn-primary btn-sm repwd" th:data="${user.id}" th:if="${user.id gt 1}">重置密码</button>
                    <button type="button" class="btn btn-success btn-sm turn-on" th:data="${user.id}" th:if="${user.id gt 1 && user.locked eq 1}">启用</button>
                    <button type="button" class="btn btn-danger btn-sm turn-off" th:data="${user.id}" th:if="${user.id gt 1 && user.locked eq 0}">禁用</button>
                  </td>
                </tr>

              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>


    <th:block th:include="include :: desk-footer" />

  <script>
    $(function (){
         $(".repwd").click(function (){
               var id=$(this).attr("data");
               layer.confirm('是否重置登录密码？', {
                 btn: ['确定', '关闭'] //按钮
               }, function(){
                  $.getJSON("/admin/repwd",{id:id},function (res) {
                        if(res.code==0)return layer.msg(res.msg);
                        return layer.alert(res.msg, {icon: 1,shadeClose: true});
                  })
               });
         })

      $(".turn-on").click(function (){
        var id=$(this).attr("data");
        layer.confirm('是否启用该账号？', {
          btn: ['确定', '关闭'] //按钮
        }, function(){
          $.getJSON("/admin/locked",{id:id,locked:0},function (res) {
            if(res.code==0)return layer.msg(res.msg);
            location.reload();
          })
        });
      })

      $(".turn-off").click(function (){
        var id=$(this).attr("data");
        layer.confirm('是否禁用该账号？', {
          btn: ['确定', '关闭'] //按钮
        }, function(){
          $.getJSON("/admin/locked",{id:id,locked:1},function (res) {
            if(res.code==0)return layer.msg(res.msg);
            location.reload();
          })
        });
      })

    })
  </script>
  </body>
</html>
